package de.baumann.browser.views.dialog

import android.content.Context
import de.baumann.browser.OdinGlideModule
import de.baumann.browser.R
import de.baumann.browser.api.net.vo.PacketMark
import kotlinx.android.synthetic.main.dialog_open_red_packet.*
/**
*@author:
*@date:2019/7/10 16:54
*@discription: 拆红包
*/
class OpenRedPacketDialog(context: Context) : BaseDialog(context) {

    private var onOpenRedPacketListener: OnOpenRedPacketListener? = null

    private var packetId: Int = 0
    override fun laoutId(): Int {
        return R.layout.dialog_open_red_packet
    }

    override fun initView() {
        ivOpenRedPacketBg.setOnClickListener {
            dismiss()
            onOpenRedPacketListener?.onOpenRedPacket(packetId)
        }
    }

    fun setPacket(packet: PacketMark): OpenRedPacketDialog {
        packetId = packet.packetId
        if (packet.avatar != null) {
            OdinGlideModule.loadWithCropAndCircle(context, packet.avatar, ivOpenRedPacketHead, R.drawable.icon_head)
        }
        ivOpenRedPacketNickname.text = packet.userName
        return this
    }

    fun setOnOpenRedPacketListener(onOpenRedPacketListener: OnOpenRedPacketListener):OpenRedPacketDialog{
        this.onOpenRedPacketListener = onOpenRedPacketListener
        return this
    }


    interface OnOpenRedPacketListener {
        fun onOpenRedPacket(packetId: Int)
    }
}